package polyparameter;

public class PolyParameter {
    public static void main(String[] args) {
        Worker lynch = new Worker("Lynch", 2500);
        Manager milan = new Manager("milan", 5000, 200000);
        PolyParameter polyParameter = new PolyParameter();
        polyParameter.showEmpAnnual(lynch);
        polyParameter.showEmpAnnual(milan);

        polyParameter.testWork(lynch);
        polyParameter.testWork(milan);
    }

    // 显示员工年薪
    public void showEmpAnnual(Employee emp) {
        System.out.println(emp.getAnnual());
    }

    public void testWork(Employee emp) {
        if (emp instanceof Worker) {
            ((Worker) emp).work(); // 强制转为 Worker 类, 向下转型
        } else if (emp instanceof Manager) {
            ((Manager) emp).manage();
        } else {
            System.out.println("do nothing");
        }
    }
}
